#include <cstddef>
#include <iostream>

#define MY_ECHOFUNPATH printf("======================== %s:%d\n", __FUNCTION__, __LINE__);
#define MY_SEP printf("------------------------\n");
// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 测试内存布局
namespace te0_0
{
    class MyClass
    {
    public:
        char a;   // 1 byte
        int b;    // 4 bytes
        short c;  // 2 bytes

        virtual void foo() {}
    };

    inline int tt0()
    {
        MY_ECHOFUNPATH;
        MyClass obj;
        std::cout << "Size of MyClass: " << sizeof(obj) << " bytes" << std::endl;

        // 打印成员地址（仅用于演示，实际不推荐这样转换）
        std::cout << "&a: " << (void *)&obj.a << std::endl;
        std::cout << "&b: " << (void *)&obj.b << std::endl;
        std::cout << "&c: " << (void *)&obj.c << std::endl;

        //==================================
        MY_SEP;
        std::cout << "vptr: 0 (隐含)" << std::endl;
        std::cout << "a: " << offsetof(MyClass, a) << std::endl;  // 8
        std::cout << "b: " << offsetof(MyClass, b) << std::endl;  // 12
        std::cout << "c: " << offsetof(MyClass, c) << std::endl;  // 16? 18?
        std::cout << "Size: " << sizeof(MyClass) << std::endl;    // 24?
        return 0;
    }
}  // namespace te0_0
